package com.efast.dmom.mes.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.bean.WmsPurchaseOrder;
import com.efast.dmom.mes.service.WmsPurchaseOrderService;

@Controller
@RequestMapping("/wmsPurchaseOrder")
public class WmsPurchaseOrderController {
	
	@Autowired
	private WmsPurchaseOrderService wmsPurchaseOrderService;
	
	@RequestMapping("/editOrAdd")
	public @ResponseBody ResultBean purchaseOrderSaveOrEdit (@RequestBody List<WmsPurchaseOrder> wmsPurchaseOrder) {
		if (wmsPurchaseOrder.get(0).getFlag().equals("add")) {
			ResultBean save = wmsPurchaseOrderService.save(wmsPurchaseOrder);
			return save;
		} else if (wmsPurchaseOrder.get(0).getFlag().equals("edit")) {
			ResultBean update = wmsPurchaseOrderService.update(wmsPurchaseOrder.get(0));
			return update;
		}
		return null;
	}
	
	@RequestMapping("/BatchDeleteOrConfirm")
	public @ResponseBody ResultBean BatchDeleteOrConfirm (@RequestBody List<WmsPurchaseOrder> list) {
		if (list.get(0).getFlag().equals("batchDelete")) {
			ResultBean batchDelete = wmsPurchaseOrderService.batchDelete(list);
			return batchDelete;
		} else if (list.get(0).getFlag().equals("batchConfirm")) {
			ResultBean batchConfirm = wmsPurchaseOrderService.batchConfirm(list);
			return batchConfirm;
		}else if (list.get(0).getFlag().equals("delete")) {
			ResultBean delete = wmsPurchaseOrderService.delete(list);
			return delete;
		}
		return null;
		
	}
	
	@RequestMapping("/saveOrEdit")
	public @ResponseBody ResultBean saveOrEdit (@RequestBody WmsPurchaseOrder wmsPurchaseOrder) {
		if (wmsPurchaseOrder.getFlag().equals("add")) {
			ResultBean itemSave = wmsPurchaseOrderService.itemSave(wmsPurchaseOrder);
			return itemSave;
		} else if (wmsPurchaseOrder.getFlag().equals("edit")) {
			ResultBean update = wmsPurchaseOrderService.update(wmsPurchaseOrder);
			return update;
		}
		return null;
		
	}
}
